package com.ruoyi.iot.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.iot.domain.Property;
import com.ruoyi.iot.service.IPropertyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 通道属性Controller
 * 
 * @author 常康
 * @date 2025-04-03
 */
@RestController
@RequestMapping("/iot/property")
public class PropertyController extends BaseController
{
    @Autowired
    private IPropertyService propertyService;

    /**
     * 查询通道属性列表
     */
    @PreAuthorize("@ss.hasPermi('iot:property:list')")
    @GetMapping("/list")
    public TableDataInfo list(Property property)
    {
        startPage();
        List<Property> list = propertyService.selectPropertyList(property);
        return getDataTable(list);
    }

    /**
     * 导出通道属性列表
     */
    @PreAuthorize("@ss.hasPermi('iot:property:export')")
    @Log(title = "通道属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Property property)
    {
        List<Property> list = propertyService.selectPropertyList(property);
        ExcelUtil<Property> util = new ExcelUtil<Property>(Property.class);
        util.exportExcel(response, list, "通道属性数据");
    }

    /**
     * 获取通道属性详细信息
     */
    @PreAuthorize("@ss.hasPermi('iot:property:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(propertyService.selectPropertyById(id));
    }

    /**
     * 新增通道属性
     */
    @PreAuthorize("@ss.hasPermi('iot:property:add')")
    @Log(title = "通道属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Property property)
    {
        return toAjax(propertyService.insertProperty(property));
    }

    /**
     * 修改通道属性
     */
    @PreAuthorize("@ss.hasPermi('iot:property:edit')")
    @Log(title = "通道属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Property property)
    {
        return toAjax(propertyService.updateProperty(property));
    }

    /**
     * 删除通道属性
     */
    @PreAuthorize("@ss.hasPermi('iot:property:remove')")
    @Log(title = "通道属性", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(propertyService.deletePropertyByIds(ids));
    }
}
